# coding: utf-8
import datetime


class GetDateTime(object):
    @classmethod
    def yesterday_time(cls):
        """
        :return:
        数据取小于等于和大于等于
        """
        now_time = datetime.datetime.now()
        yesterday_time = now_time - datetime.timedelta(days=1)
        start_time = datetime.datetime(yesterday_time.year, yesterday_time.month, yesterday_time.day, 0, 0, 0)
        end_time = datetime.datetime(yesterday_time.year, yesterday_time.month, yesterday_time.day, 23, 59, 59, 999999)
        return start_time, end_time

    @classmethod
    def today_time(cls):
        """
        :return:
        数据取小于等于和大于等于
        """
        now_time = datetime.datetime.now()
        start_time = datetime.datetime(now_time.year, now_time.month, now_time.day, 0, 0, 0)
        end_time = datetime.datetime(now_time.year, now_time.month, now_time.day, 23, 59, 59, 999999)
        return start_time, end_time

    @classmethod
    def today_date(cls):
        return datetime.date.today()

    @classmethod
    def yesterday_date(cls):
        now_time = datetime.date.today()
        return now_time - datetime.timedelta(days=1)

    @classmethod
    def tomorrow(cls):
        now_time = datetime.date.today()
        return now_time + datetime.timedelta(days=1)

    @classmethod
    def this_month(cls):
        """
        :return:
        """
        now_month = datetime.date.today()
        days_count = datetime.timedelta(days=now_month.day - 1)
        this_month = now_month - days_count
        return this_month

    @classmethod
    def last_month(cls):
        t_month = cls.this_month()
        l_month = t_month - datetime.timedelta(days=t_month.day)
        start_time = l_month - datetime.timedelta(days=l_month.day - 1)
        return start_time

    @classmethod
    def get_tow_hours_ago(cls):
        now_time = datetime.datetime.now()
        start_time = now_time - datetime.timedelta(hours=2)
        return start_time

    @classmethod
    def get_days_ago(cls, days):
        now_time = datetime.datetime.now()
        return now_time - datetime.timedelta(days=days)

    @classmethod
    def format_datetime(cls, date_format="%Y%m%d%H%M%S"):
        """
        :param date_format:
        :return:
        """
        return datetime.datetime.now().strftime(date_format)

    @classmethod
    def timedelta_mouth(cls, month, now_time=None):
        if not now_time:
            now_time = datetime.datetime.now()
        compare_month = now_time.month + month
        if compare_month > 12:
            year = now_time.year + 1
            month = compare_month - 12
            day = now_time.day
        else:
            year = now_time.year
            month = compare_month
            day = now_time.day
        return datetime.datetime(year, month=month, day=day)
